
(function () {
  new Swiper('.swiper-container', {
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    loop: true,
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
      bulletClass: 'swiper-pagination-bullet my-bullet',
      bulletActiveClass: 'swiper-pagination-bullet-active my-bullet-active',
    },
  });

  let wow = new WOW({
    boxClass: 'wow',
    animateClass: 'animated',
    offset: 0,
    mobile: true,
    live: true
  });
  wow.init();
})()

window.addEventListener('load', function () {
  init();

  let tapTop = document.querySelector('.fixed-top')
  let videoBox = document.querySelector('.video').offsetTop

  pageScroll()
  window.addEventListener('scroll', pageScroll)

  tapTop.addEventListener('click', function () {
    animationTapTop(window, 0);
  })

  function pageScroll() {
    window.pageYOffset >= videoBox
      ? tapTop.style.display = 'block'
      : tapTop.style.display = 'none';
  }

});

function init() {
  let processHead = document.querySelector(".process-content-head")
  let processBody = document.querySelector(".process-content-body")
  let processHeadList = document.querySelectorAll('.process-content-head span')
  let processBodyList = document.querySelectorAll('.process-item')
  let processHeight = window.getComputedStyle(processBodyList[0]).getPropertyValue('height')

  processBody.style.height = processHeight;

  processHead.addEventListener("click", function (e) {
    let processIndex = e.target.getAttribute('data-index') - 0;
    processHeight = window.getComputedStyle(processBodyList[processIndex]).getPropertyValue('height')

    processBody.style.height = processHeight;

    processHeadList.forEach((item, index) => {
      index == processIndex
        ? item.classList.add("process-active")
        : item.classList.remove("process-active")
    })

    processBodyList.forEach((item, index) => {
      index == processIndex
        ? item.classList.add("active")
        : item.classList.remove("active")
    })
  })
}

//返回顶部的动画函数
function animationTapTop(obj, target, callback) {
  clearInterval(obj.timer)
  obj.timer = setInterval(function () {
    if (window.pageYOffset == target) {
      clearInterval(obj.timer)
      callback && callback();
    } else {
      var step = (target - window.pageYOffset) / 10
      step = step > 0 ? Math.ceil(step) : Math.floor(step)
      window.scroll(target, window.pageYOffset + step)
    }
  }, 15)
}